<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="/web/public/js/jquery-2.2.4.min.js"></script>
</head>
<body>
<style type="text/css">
    /* Border styles */
    #table-1 thead, #table-1 tr {
        border-top-width: 1px;
        border-top-style: solid;
        border-top-color: rgb(230, 189, 189);
    }

    #table-1 {
        border-bottom-width: 1px;
        border-bottom-style: solid;
        border-bottom-color: rgb(230, 189, 189);
    }

    /* Padding and font style */
    #table-1 td, #table-1 th {
        padding: 5px 10px;
        font-size: 12px;
        font-family: Verdana;
        color: rgb(177, 106, 104);
    }

    /* Alternating background colors */
    #table-1 tr:nth-child(even) {
        background: rgb(238, 211, 210)
    }

    #table-1 tr:nth-child(odd) {
        background: #FFF
    }
</style>
<div>
    <input type="button" value="图文" id="news" class="button" onclick="toUrl('news');"/>
    <input type="button" value="图片" id="image" class="button" onclick="toUrl('image');"/>
    <input type="button" value="视频" id="video" class="button" onclick="toUrl('video');"/>
    <input type="button" value="语音" id="voice" class="button" onclick="toUrl('voice');"/>
    <input type="button" value="生成菜单" id="voice" class="button" onclick="setMenu();"/>
    <input type="button" value="清除缓存" class="button" onclick="clearCache();"/>
</div>
<input type="hidden" id="hidden" value="<?php echo $type; ?>"/>
<table id="table-1" style="width: 100%;text-align: left;">
    <tr>
        <th style="width: 500px;text-align: center;">ID</th>
        <th>标题</th>
    </tr>
    <?php
    foreach ($list as $val) {
        ?>
        <tr>
            <td><?php echo $val['media_id']; ?></td>
            <td><?php echo $val['name']; ?></td>
        </tr>
        <?php
    }
    ?>
</table>
<div id="urlText"></div>
<script type="text/javascript">
    var type = document.getElementById('hidden').value;
    document.getElementById(type).style.color = 'green';
    function toUrl(type) {
        window.location.href = './get-media?type=' + type;
    }
    function clearCache() {
        window.location.href = './get-media?clear=clear'
    }
    function setMenu() {
        $.ajax({
            type: "post",
            url: './set-menu',
            dataType: 'json',
            success: function(res_data) {
                if(res_data.errmsg == 'ok') {
                   alert('设置成功！')
                } else {
                    alert('设置失败！'+res_data.errmsg )
                }
            },
            error: function() {
                alert('设置失败');
            }
        });
    }
</script>
</body>
</html>